import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '@/views/Login/Login'
import Reg from '@/views/Reg/Reg'
import Home from '@/views/Menus/Home/Home.vue'
import UserInfo from '@/views/Menus/User/UserInfo.vue'
import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
import UserPwd from '@/views/Menus/User/UserPwd.vue'
Vue.use(VueRouter)
import Main from '@/views/Main/Main.vue'

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
 {
   path: '/login', 
   name:'login',
   component: Login
 },
 {
   path: '/reg',
   name:'reg',
   component: Reg
 },
 {
    path: '/',
    name:'main',
    // 重定向
    redirect: '/home',
    component: Main,
    // 二级路由
    children: [
    {
      path: 'home', // 首页
      name:'home',
      component: Home,
    },
    {
      path: 'user-info', // 修改用户信息
      name:'user-info',
      component: UserInfo,
    },
    {
      path: 'User-avatar', // 修改头像
      name: 'User-avatar',
      component: UserAvatar
    },
    {
      path: 'User-pwd', // 重置密码
      name: 'User-pwd',
      component: UserPwd
    }
    ]
 }
]
const router = new VueRouter({
  routes
})

export default router
